
$(function () {
    //根据屏幕分辨率自适应浏览器布局高度
    window.onresize = doresize;
    doresize();

    $(".content-body").on("mouseover",function(){
        var fixHeight = $(this).height();
        var tableHeight = $(this).find("table").height();
        var fixWidth = $(this).width();
        var tableWidth = $(this).find("table").width();

        if(tableHeight>(fixHeight+10)){
            $(this).css("overflow-y","scroll");
        }

        if(tableWidth>(fixWidth+10)){
            $(this).css("overflow-X","scroll");
        }
    }).on("mouseout",function(){
        $(this).css("overflow-y","hidden");
        $(this).css("overflow-X","hidden");
        //$(this).find('table').css("width",$(this).width());
    });
});

//字符串拼接
function stringFormat() {
    if (arguments.length == 0)
        return null;

    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

//设置两个表格的列宽
function setTargetTableColumnWidth(source,target){
    var ths = $(source).find("tr th");
    $.each($(target).find("tr"),function(){
        var tds = $(this).find("td");
        if(tds.length>0 && ths.length>0 && ths.length>=tds.length){
            for (var i = 0; i < tds.length; i++) {
                $(tds[i]).attr("width",ths[i].width);
            }
        }
    })
}

function setSourceTableColumnWidth(source,target){
    var ths = $(source).find("tr th");
    
     var tds= $(target).find("tr").eq(0).find("td");
     
     if(tds.length>0 && ths.length>0 && ths.length>=tds.length){
         for (var i = 0; i < tds.length; i++) {
             $(ths[i]).attr("width",tds[i].clientWidth);
         }
     }
    
}

function doresize() {
    var height = $(window).height();

    $(".main").css("height",height);
    $(".main-body").css("height",height-$(".main-top").height()-$(".main-footer").height()-$(".main-top-bottom").height());

    $(".content-body").css("height",$(".main-body").height()-60);
    var haveFixBody = $(".fix-head").next();
    if(haveFixBody.length>0){
        haveFixBody.css("height",haveFixBody.height()-$(".fix-head").height());
    }
    if($(".query-condition").length>0){
        $(".content-body").css("height", $(".content-body").height()-$(".query-condition").outerHeight(true));
    }
}
